package com.sky.controller.admin;

import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        log.info("分页查询菜品: {}", dishPageQueryDTO);
        PageResult page = dishService.page(dishPageQueryDTO);
        return Result.success(page);
    }

    /**
     * 根据分类id查询菜品
     */
     @GetMapping("/list")
     public Result<List<Dish>> list(Long categoryId) {
         log.info("根据分类id查询菜品: {}", categoryId);
         List<Dish> dishList = dishService.list(categoryId);
         return Result.success(dishList);
     }

    /**
     * 菜品起售，停售
     */
     @PostMapping("/status/{status}")
     public Result updateStatus(@PathVariable Integer status, Long id) {
         log.info("菜品起售，停售: {}, {}", status, id);
         dishService.updateStatus(status, id);
         return Result.success();
     }

    /**
     * 根据id查询菜品
     */
    @GetMapping("/{id}")
    public Result<Dish> getById(@PathVariable Long id) {
        log.info("根据id查询菜品: {}", id);
        //Dish dish = dishService.getById(id);
        return Result.success();
    }

}
